package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Answer extends BaseObject {
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("voteItem", voteItem).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Answer))
			return false;
		Answer castOther = (Answer) other;
		return new EqualsBuilder().append(id, castOther.id).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).toHashCode();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name = "vote_item_id")
	public VoteItem getVoteItem() {
		return voteItem;
	}

	public void setVoteItem(VoteItem voteItem) {
		this.voteItem = voteItem;
	}
	@ManyToOne(cascade={CascadeType.MERGE})
	@JoinColumn(name="poll_id")
	public Poll getPoll() {
		return poll;
	}

	public void setPoll(Poll poll) {
		this.poll = poll;
	}

	private Long id;
	private VoteItem voteItem;	
	private Poll poll;

}
